package com.bridgeintelligent.tag.webserver.dim.mgmt.service.export.excel;

import com.bridgeintelligent.tag.webserver.dim.mgmt.api.export.ExcelReaderCheckRsp;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDate;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

/**
 * @author JackCheung
 * @date 2020/7/6 3:45 PM.
 * description:
 */
public interface IDimExcelReaderService extends IDimExcelService{

    String FILE_NAME_TMP = "标签模型TMP";

    DateTimeFormatter YYYY_MM_DD = DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.CHINA);

    /**
     * 过滤掉生效日期大于当前时间的数据
     *
     * @param effectiveTime effectiveTime
     * @return boolean
     */
    default boolean fetchDate(String effectiveTime) {
        LocalDate effectiveDate = LocalDate.parse(effectiveTime, YYYY_MM_DD);
        return System.currentTimeMillis() > effectiveDate.atStartOfDay(ZoneOffset.ofHours(8))
                                                         .toInstant()
                                                         .toEpochMilli();
    }

    /**
     * 上传excel文件，并获取变化结果
     *
     * @param excelFile excelFile
     * @return ExcelReaderCheckRsp
     */
    ExcelReaderCheckRsp upload(MultipartFile excelFile);
}
